// app.js
App({
  onLaunch() {
    var openid = wx.getStorageSync('openid')
    if(!openid) {
      var that = this
      wx.login({
        success: function (res) {
          wx.request({
            url: that.globalData.apiUrl + 'user/login',
            data: {
              code: res.code
            },
            method: 'POST',
            success: function (res) {
              var result = res.data
              if (result.status == 200) {
                console.log(result.data.openid)
                wx.setStorageSync('openid', result.data.openid)
              }
            }
          })
        }
      })
    }
    
  },
  globalData: {
    apiUrl: 'http://school-news.test/api/v1/'
  }
})
